package lp.polimi.treefinder.utils;


import lp.polimi.treefinder.R;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.pm.ActivityInfo;
import android.content.res.Configuration;

public class UIUtils {

	private UIUtils () {
		
	}
	
	public static void lockScreenRotation(Activity activity) {
		int currentOrientation = activity.getResources().getConfiguration().orientation;
		if (currentOrientation == Configuration.ORIENTATION_LANDSCAPE) {
		   activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE);
		} else {
			activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
		}
	}

	public static void unlockScreenRotation(Activity activity) {
		activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
	}

	public static void showWelcomeDialog(final Activity activity) {
		new AlertDialog.Builder(activity).setView(activity.getLayoutInflater().inflate(R.layout.welcome_dialog, null)).setTitle(R.string.welcome_title).
		setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
			
			@Override
			public void onClick(DialogInterface dialog, int which) {
				activity.getSharedPreferences("firstRun", Activity.MODE_PRIVATE).edit().putBoolean("firstRun", false).commit();
			}
		}).show();
	}
}
